package com.kgc.sbt.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.kgc.sbt.api.UserApi;

import com.kgc.sbt.config.WechatAuthConfig;
import com.kgc.sbt.beans.*;
import com.kgc.sbt.service.UserService;

import com.kgc.sbt.utils.*;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.PasswordAuthentication;
import java.util.*;


/**
 * Created on 2021/8/18.
 * <p>
 * Author: 190120
 * <p>
 * Description:
 */
@Service
@Slf4j
public class UserServiceImpl implements UserService {


    @Reference(timeout = 30000, retries = 0)
    private UserApi userApi;

    @Autowired
    private WechatAuthConfig wechatAuthConfig;
    @Autowired
    private RedisUtils redisUtils;
    @Autowired
    private UserService userService;

    @Override
    public UserLogin queryUserEntryById(Integer userId) {
        return userApi.queryUserEntryById(userId);
    }

    @Override
    public boolean modPasswordById(Integer userId, String password) {
        return userApi.updatePasswordById(userId, password);
    }

    @Override
    public boolean modPhoneById(Integer userId, String newPhone) {
        return userApi.updatePhoneById(userId, newPhone);
    }

    @Override
    public boolean modUserNameById(Integer userId, String newName) {
        return userApi.updateUserNameById(userId, newName);
    }

    @Override
    public Integer userSigned(Integer userId) {
        return userApi.userSigned(userId);
    }

    @Override
    public Sign querySignByUserId(Integer userId) {
        return userApi.querySignByUserId(userId);
    }

    @Override
    public Boolean addPoints(Integer userId, Integer points) {
        return userApi.addPoints(userId, points);
    }

    @Override
    public UserLogin queryUserByUserId(Integer userId) {
        return userApi.queryUserByUserId(userId);
    }

    @Override
    public UserLogin queryByOpenId(String openId) {
        return userApi.queryByOpenId(openId);
    }

    @Override
    public boolean updateUserByPhone(String phoneNo, String openId) {
        return userApi.updateUserByPhone(phoneNo, openId);
    }


    @Override
    public UserLogin queryByPhone(String phone) {
        return userApi.querByPhone(phone);
    }

    @Override
    public void insertUser(String phone, String password, String userName) {
        password = EncodeUtils.testDigest(password);
        userApi.insertUser(phone, password, userName);
    }

    @Override
    public RequestResult<Map<String, Object>> sendCode(String phone) {
        return userApi.sendCode(phone);
    }


    @Override
    public void saveToken(String token, Integer userId) {
        userApi.saveToken(token, userId);
    }

    @Override
    public void delToken(String token) {
        userApi.delToken(token);
    }

    @Override
    public Boolean queryVipByUserId(Integer userId) {
        return userApi.queryVipByUserId(userId);
    }

    @Override
    public void insertVipByUserId(Integer userId) {
        userApi.insertVipByUserId(userId);
    }
}
